<template>
  <h1>计算器练习</h1>
  <input type="text" v-model="num1" placeholder="请输入数1">
  <input type="text" v-model="num2" placeholder="请输入数2">
  <button @click="f('+')">加</button>
  <button @click="f('-')">减</button>
  <button @click="f('*')">乘</button>
  <button @click="f('/')">除</button>
  <h4>结果是:{{result}}</h4>
</template>

<script setup>
import {ref} from 'vue';
const num1 = ref('');
const num2 = ref('');
const result = ref('');
const f = (o) => {
  if(num2.value==0&&o=='/'){
    alert('除数不能为0');
    return;
  }
  result.value = eval(num1.value+o+num2.value);
}
</script>


<style scoped>

</style>